<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-collapse [lvMultiExpansion]="'false'" lvType="simple">
    <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="true">
        <lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup">
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{'protection_clients_label' | i18n}}
                    <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_kubernetes_host_help_label' | i18n}}"
                         class="configform-constraint"></i>
                </lv-form-label>
                <lv-form-control>
                    <lv-select [lvOptions]="hostOptions" formControlName="proxyHost" lvValueKey='value'
                        lvMode="multiple" [lvContentTemplate]="contentTpl"></lv-select>
                    <ng-template #contentTpl let-item>
                        <lv-group lvGutter="4px">
                            <i lv-icon="{{
                                  item.linkStatus === dataMap.resource_LinkStatus_Special.normal.value ? 'aui-host-online' : 'aui-host-offline'
                                }}"></i>
                            <span>{{ item.label }}</span>
                        </lv-group>
                    </ng-template>
                </lv-form-control>
            </lv-form-item>
            <!-- statefulset -->
            <ng-container *ngIf="resourceType === dataMap.Resource_Type.KubernetesStatefulset.value">
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_protect_pre_script_label' | i18n}}
                        <i lv-icon="aui-icon-help"  class="configform-constraint"
                            lv-tooltip="{{'protection_recovery_advance_script2_label' | i18n }}" lvColorState="true">
                        </i>
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]="scriptErrorTip">
                        <input formControlName="before_protect_script" lv-input />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_protect_post_script_label' | i18n}}
                        <i lv-icon="aui-icon-help"  class="configform-constraint"
                            lv-tooltip="{{'protection_recovery_advance_script2_label' | i18n }}" lvColorState="true">
                        </i>
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]="scriptErrorTip">
                        <input formControlName="after_protect_script" lv-input />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_protect_fail_script_label' | i18n}}
                        <i lv-icon="aui-icon-help"  class="configform-constraint"
                            lv-tooltip="{{'protection_recovery_advance_script2_label' | i18n }}" lvColorState="true">
                        </i>
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]="scriptErrorTip">
                        <input formControlName="protect_failed_script" lv-input />
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
            <!-- namespace -->
            <ng-container *ngIf="resourceType === dataMap.Resource_Type.KubernetesNamespace.value">
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_overwrite_policy_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control>
                        <lv-radio-group formControlName="slaOverwrite">
                            <lv-group [lvGutter]="'8px'" lvDirection='vertical' class="mgt-8">
                                <lv-radio [lvValue]="true" [lvDisabled]="resourceData.protectedObject?.slaId">
                                    {{'protection_overwrite_statefulset_sla_label' | i18n}}
                                </lv-radio>
                                <lv-radio [lvValue]="false" [lvDisabled]="resourceData.protectedObject?.slaId">
                                    {{'protection_not_overwrite_statefulset_sla_label' | i18n}}
                                </lv-radio>
                            </lv-group>
                        </lv-radio-group>
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_apply_policy_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control>
                        <lv-checkbox-group formControlName="slaPolicy" [lvDisabled]="disabled">
                            <lv-group [lvGutter]="'8px'" lvDirection='vertical' class="mgt-8">
                                <lv-checkbox lvValue="APPLY_TO_ALL">
                                    {{'protection_apply_sla_in_namespace_label' | i18n:[selectedTitle] }}
                                </lv-checkbox>
                                <lv-checkbox lvValue="APPLY_TO_NEW">
                                    {{'protection_apply_sla_in_new_statefulset_label' | i18n:[selectedTitle]}}
                                </lv-checkbox>
                            </lv-group>
                        </lv-checkbox-group>
                    </lv-form-control>
                </lv-form-item>
                <aui-protect-filter [formGroup]="formGroup" [valid$]="valid$" [resType]="resourceType">
                </aui-protect-filter>
            </ng-container>
        </lv-form>
    </lv-collapse-panel>
</lv-collapse>

<ng-template #titleTpl>
    <lv-group lvGutter='8px'>
        <span class="aui-h3">{{'common_advanced_label'|i18n}}</span>
    </lv-group>
</ng-template>
